<?php
namespace App\Common\Providers;

use App\Common\Facades\ComEmailCodeFacade;
use App\Common\Facades\ComSmsFacade;
use App\Common\Facades\ObsFacade;
use App\Common\Facades\OfficeFacade;
use App\Common\Facades\OssFacade;
use App\Common\Facades\OssFileFacade;
use App\Common\Facades\PinYinFacade;
use App\Common\Facades\SysEmailFacade;
use App\Common\Facades\UploadFacade;
use App\Common\Facades\UploadFileFacade;
use App\Common\Models\ComEmailCodeModel;
use App\Common\Models\ComOssETagModel;
use App\Common\Models\ComSmsModel;
use App\Common\Services\ComEmailCodeService;
use App\Common\Services\ComSmsService;
use App\Common\Services\ObsService;
use App\Common\Services\OfficeService;
use App\Common\Services\OssFileService;
use App\Common\Services\OssService;
use App\Common\Services\PinYinService;
use App\Common\Services\UploadFileService;
use App\Common\Services\UploadService;
use App\Providers\EventServiceProvider;
use App\Common\Services\SysEmailTaskService;

class CommonProvider extends EventServiceProvider
{

    /**
     * 注册绑定门面
     */
    public function register()
    {
        //注册上传接口
        $this->registerUpload();
        //OSS
        $this->registerOss();
        //注册公共短信服务
        $this->registerComSms();
        //注册短信验证码
        $this->registerComEmailCode();

        $this->registerPinYin();

        $this->app->bind(OssFileFacade::class, function () {
            return app()->make(OssFileService::class);
        });
        $this->app->bind(UploadFacade::class, function () {
            return app()->make(UploadService::class);
        });

        $this->app->bind(ObsService::class, function () {
            return new ObsService(new ComOssETagModel());
        });
        //obs 文件上传
        $this->app->bind(ObsFacade::class, function () {
            return app()->make( ObsService::class);
        });
        $this->app->bind(OfficeFacade::class, function () {
            return app()->make( OfficeService::class);
        });
    }

    /**
     * 注册OSS
     */
    protected function registerOss(){

        $this->app->bind(OssService::class, function () {
            return new OssService(new ComOssETagModel());
        });
        $this->app->bind(OssFacade::class, function () {
            return app()->make(OssService::class);
        });
    }

    /**
     * 注册OSS
     */
    protected function registerUpload(){
        $this->app->bind(UploadFileFacade::class, function () {
            return app()->make(UploadFileService::class);
        });
    }

    /**
     * 注册公共短信验证码发送服务
     * */
    protected function registerComSms(){
        $this->app->bind(ComSmsService::class, function () {
            return new ComSmsService(new ComSmsModel());
        });
        $this->app->bind(ComSmsFacade::class, function () {
            return app()->make(ComSmsService::class);
        });
    }

    /**
     * 注册公共邮箱验证码发送服务
     * */
    protected function registerComEmailCode()
    {
        $this->app->bind(ComEmailCodeService::class, function () {
            return new ComEmailCodeService(new ComEmailCodeModel());
        });
        $this->app->bind(ComEmailCodeFacade::class, function () {
            return app()->make(ComEmailCodeService::class);
        });
        $this->app->bind(SysEmailFacade::class, function () {
            return app()->make(SysEmailTaskService::class);
        });
    }

    /**
     * 拼音
     */
    protected function registerPinYin()
    {
        $this->app->bind(PinYinFacade::class, function () {
            return app()->make(PinYinService::class);
        });
    }

}
